package org.pku_uestc.hackathon.handler;

import org.pku_uestc.hackathon.bean.ISensorHandler;

import android.content.Context;
import android.util.SparseArray;


/**
 * 根据配置文件的映射,构造特定的ISensorHandler
 * 
 * @author Jason wu
 */

public class SensorHandlerFactory {
	private Context context;
	
	public SensorHandlerFactory(Context context){
		this.context = context;
	}
	
	private SparseArray<ISensorHandler> array = new SparseArray<ISensorHandler>(ISensorHandler.TYPE_SIZE);
	
	public ISensorHandler getSensorHandler(int type){
		if(array.get(type)!=null)
			return array.get(type);
		
		ISensorHandler temp = null;
		switch(type){
		case ISensorHandler.TYPE_HIGHTEMPHANDLER:
			temp = new HighTempHandler(context);
			break;
		case ISensorHandler.TYPE_LOWTEMPHANDLER:
			temp = new LowTempHandler(context);
			break;
		}
		
		if(temp != null)
			array.put(type, temp);
		return temp;
	}
}
    